/**
 * 
 */
package com.td.framework.webmanager.qxgl.service.impl;

import java.util.Iterator;
import java.util.List;

import com.td.framework.webmanager.common.TreeCreateHandler;
import com.td.framework.webmanager.domain.AppsysQxfwjlgx;
import com.td.framework.webmanager.domain.AppsysQxgx;
import com.td.framework.webmanager.domain.AppsysQxxx;
import com.td.framework.webmanager.domain.AppsysQxygns;
import com.td.framework.webmanager.domain.AppsysYmgnBean;
import com.td.framework.webmanager.domain.AppsysYmxzfwjl;
import com.td.framework.webmanager.domain.AppsysYmxzfwjlBean;
import com.td.framework.webmanager.domain.YmxztjBean;
import com.td.framework.webmanager.qxgl.dao.QxglDao;
import com.td.framework.webmanager.qxgl.service.QxglService;
import com.td.framework.webmanager.qxgl.service.QxglService;
import com.td.framework.webmanager.qxygns.dao.QxygnsDao;
import com.td.framework.webmanager.ymgn.dao.YmgnDao;

/**
 * 
 * Title:权限处理业务层实现类 Description: 实现业务层权限处理方法 Copyright: Copyright (c) 2008
 * Company 北京水软科技有限公司
 * 
 * @author FLT006
 * @version 1.0
 */
public class QxglServiceImpl implements QxglService {

	private QxglDao qxglDao = null;// 权限Dao;
	private QxygnsDao qxygnsDao = null;// 功能树Dao;
	private YmgnDao ymgnDao = null;// 页面功能Dao;

	/**
	 * @toDo:保存权限信息;
	 * @param yhzbhs
	 * @param ymbhs
	 * @return boolean;
	 */
	public boolean addAppsysQxxx(String yhbhs, String[] ymbhs) {
		return this.qxglDao.addAppsysQxxx(yhbhs, ymbhs);
	}

	/**
	 * @toDo:删除权限信息;
	 * @return boolean;
	 */
	public boolean deleteAppsysQxxx() {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * @toDo:查询系统功能树List;
	 * @return list;
	 */
	@SuppressWarnings("unchecked")
	public List<AppsysQxygns> getSystemTreeList() {
		List list = qxygnsDao.getTreeList();
		return list;
	}

	/**
	 * @toDo:查询当前用户组功能树List;
	 * @param yhzbh,flag
	 * @return list;
	 */
	@SuppressWarnings("unchecked")
	public List<AppsysQxygns> getRightTreeList(String yhzbh, Long flag,int type) {
		List list = qxygnsDao.getRightTreeList(yhzbh, flag, type);
		return list;
	}

	/**
	 * @toDo:通过页面编号生成功能树
	 * @param ymbhs
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List getRightTreeList(String[] ymbhs) {
		return qxygnsDao.getRightTreeList(ymbhs);
	}

	/**
	 * @toDo:生成系统权限树所需的xml格式字符流
	 * @param xmlName
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String getSystemTreeXml(String xmlName) {
		//List list = qxygnsDao.getXmlTreeList();
		List list = qxygnsDao.getRightTreeList("-1", new Long(1), 1);
		AppsysQxygns appsysQxygns = new AppsysQxygns();
		TreeCreateHandler treeCreateHandler = new TreeCreateHandler();
		try {
			treeCreateHandler.startDocument();
			if (list != null) {
				for (Iterator iterator = list.iterator(); iterator.hasNext();) {
					appsysQxygns = (AppsysQxygns) iterator.next();
					treeCreateHandler.startElement(appsysQxygns);
					treeCreateHandler.endElement(appsysQxygns);
				}
			}
			treeCreateHandler.endDocument();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return treeCreateHandler.getResult(xmlName).toString();
	}

	/**
	 * @toDo::生成当前用户组权限树所需的xml格式字符流
	 * @param xmlName,
	 * @param  yhzbh 用户或者用户组编号
	 * @param flag 0表示用户组、1表示用户 
	 * @param type 0 已授权,1 未授权
	 * @return
	 */
	public String getCurrentTreeXml(String xmlName, String yhzbh, Long flag,
			int type) {
		List list = qxygnsDao.getRightTreeList(yhzbh, flag, type);
		AppsysQxygns appsysQxygns = new AppsysQxygns();
		TreeCreateHandler treeCreateHandler = new TreeCreateHandler();
		try {
			treeCreateHandler.startDocument();
			if (list != null) {
				for (Iterator iterator = list.iterator(); iterator.hasNext();) {
					appsysQxygns = (AppsysQxygns) iterator.next();
					treeCreateHandler.startElement(appsysQxygns);
					treeCreateHandler.endElement(appsysQxygns);
				}
			}
			treeCreateHandler.endDocument();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return treeCreateHandler.getResult(xmlName).toString();
	}

	/**
	 * @toDo::生成空的权限树所需的xml格式字符流
	 * @param xmlName
	 * @return
	 */
	public String getCurrentTreeXml(String xmlName) {
		TreeCreateHandler treeCreateHandler = new TreeCreateHandler();
		try {
			treeCreateHandler.startDocument();
			treeCreateHandler.endDocument();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return treeCreateHandler.getResult(xmlName).toString();
	}

	/**
	 * @toDo:保存用户组页面级功能权限;
	 * @param qxbh
	 * @param ymbh
	 * @param gnbhs
	 * @param qxfwjlgxs
	 * @return boolean;
	 */
	public boolean addYmgnRight(String qxbh, String ymbh, String[] gnbhs,List<AppsysQxfwjlgx> qxfwjlgxs) {
		return ymgnDao.addYmgnRight(qxbh, ymbh, gnbhs,qxfwjlgxs);
	}

	/**
	 * @toDo:查询权限信息List;
	 * @return list;
	 */
	public List<AppsysQxxx> fingby() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * @toDo:查询权限信息;
	 * @return AppsysQxxx;
	 */
	public AppsysQxxx getAppsysQxxx() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * @toDo:得到与权限结合的功能List;
	 * @param qxbh
	 * @param ymbh
	 * @param type 1 为页面功能, 2 为页面限制字段
	 * @return list;
	 */
	@SuppressWarnings("unchecked")
	public List<AppsysYmgnBean> findAppsysYmgnBean(Long qxbh, String ymbh,
			int type) {
		return ymgnDao.findAppsysYmgnBean(qxbh, ymbh, type);
	}

	/**
	 * toDo:通过权限编号、页面编号查询限制访问记录条件
	 * 
	 * @param qxbh
	 * @param ymbh
	 * @return list;
	 */
	public List<AppsysYmxzfwjlBean> findAppsysYmxzfwjlBean(Long qxbh,
			String ymbh) {
		return ymgnDao.findAppsysYmxzfwjlBean(qxbh, ymbh);
	}

	/**
	 * @toDo: 更新权限信息;
	 * @param qxxx
	 * @return boolean;
	 */
	public boolean updateAppsysQxxx(AppsysQxxx qxxx) {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * @toDo:通过用户组编号得到对应的权限编号;
	 * @param yhzbh
	 * @param flag
	 * @return qxbh;
	 */
	public Long getQxbh(String yhzbh, Long flag) {
		return qxglDao.getQxbh(yhzbh, flag);
	}
	/**
	 * toDo:通过权限编号、限制条件编号查询条件列表
	 * @param qxbh
	 * @param xzbh
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<YmxztjBean> findYmxztjBean(Long qxbh, String xzbh)
	{
		AppsysYmxzfwjl ymfwjl=ymgnDao.getAppsysYmfwjl(Long.parseLong(xzbh));
		String conSql = "";
		if(ymfwjl!=null)
		{
			conSql = ymfwjl.getXztj();
		}
		return ymgnDao.findYmxztjBean(qxbh, xzbh,conSql);
	}
	/**
	 * @toDo:get功能树Dao ;
	 * @return the qxygnsDao
	 */
	public QxygnsDao getQxygnsDao() {
		return qxygnsDao;
	}

	/**
	 * @toDo:set功能树Dao ;
	 * @param qxygnsDao
	 *            the qxygnsDao to set
	 */
	public void setQxygnsDao(QxygnsDao qxygnsDao) {
		this.qxygnsDao = qxygnsDao;
	}

	/**
	 * @toDo:get页面功能Dao ;
	 * @return the ymgnDao
	 */
	public YmgnDao getYmgnDao() {
		return ymgnDao;
	}

	/**
	 * @toDo:set页面功能Dao ;
	 * @param ymgnDao
	 *            the ymgnDao to set
	 */
	public void setYmgnDao(YmgnDao ymgnDao) {
		this.ymgnDao = ymgnDao;
	}

	/**
	 * @toDo:通过用户/用户组编号查询权限编号;
	 * @param yhbhs
	 * @return qxbhs;
	 */
	@SuppressWarnings("unchecked")
	public String getQxbh(String yhbhs) {
		return this.qxglDao.getQxbh(yhbhs);
	}
	/**
	 * @toDo: 根据页面编号、功能编号、功能类型读取权限关系;
	 * @param ymbh
	 * @param gnbh
	 * @param qxbz
	 * @return appsysQxgx
	 */
	@SuppressWarnings("unchecked")
	public AppsysQxgx getAppsysQxgx(String ymbh,String gnbh,int qxbz)
	{
		return qxglDao.getAppsysQxgx(ymbh, gnbh, qxbz);
	}

	public QxglDao getQxglDao() {
		return qxglDao;
	}

	public void setQxglDao(QxglDao qxglDao) {
		this.qxglDao = qxglDao;
	}
}
